package com.apabi.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.apabi.common.pojo.JqGridResult;
import com.apabi.mapper.SysIpStatsMapper;
import com.apabi.pojo.SysIpStats;
import com.apabi.service.SysIpStatsService;
import org.n3r.idworker.Sid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * Created by zhangxh.apabi on 2017/9/22.
 */
@Service
public class SysIpStatsServiceImpl implements SysIpStatsService{


    @Autowired
    private SysIpStatsMapper sysIpStatsMapper;

    @Autowired
    private Sid sid;

    @Override
    public void saveSysIpStats(SysIpStats sysIpStats) {
        String itemId = sid.nextShort();
        sysIpStats.setId(itemId);
        sysIpStatsMapper.insert(sysIpStats);
    }

    @Override
    public JqGridResult querySysIpStatsList(String name, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<SysIpStats> list =  sysIpStatsMapper.selectAll();
        PageInfo<SysIpStats> pageList = new PageInfo<SysIpStats>(list);

        JqGridResult grid = new JqGridResult();
        grid.setTotal(pageList.getPages());
        grid.setRows(list);
        grid.setPage(pageList.getPageNum());
        grid.setRecords(pageList.getTotal());
        return grid;
    }

    @Override
    public SysIpStats querySysIpStatsById(String sysIpStatsId) {
        return sysIpStatsMapper.selectByPrimaryKey(sysIpStatsId);
    }

    @Override
    public void deleteSysIpStatsById(String sysIpStatsId) {
        sysIpStatsMapper.deleteByPrimaryKey(sysIpStatsId);
    }

    @Override
    public void updateSysIpStatsById(SysIpStats sysIpStats) {
        sysIpStatsMapper.updateByPrimaryKey(sysIpStats);
    }

    @Override
    public List<Map<String, Object>> querySysIpStatsByDateAndtoken(String date, String token) {
        return sysIpStatsMapper.querySysIpStatsByDateAndtoken(date,token);
    }

}
